]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
[MessageTray] remove Source IDs
authorDan Winship <danw@gnome.org>
Mon, 9 Aug 2010 17:18:15 +0000 (13:18 -0400)
committerDan Winship <danw@gnome.org>
Thu, 26 Aug 2010 14:52:01 +0000 (10:52 -0400)
The tray itself does not actually need them, and to make status icon
sources work correctly the NotificationDaemon will need to be tracking
its sources by two separate IDs, so the existing system won't work.

Also remove MessageTray.removeSourceByApp(), which is
NotificationDaemon-specific, and implement the functionality in
notificationDaemon.js instead.

https://bugzilla.gnome.org/show_bug.cgi?id=627303

js/ui/messageTray.js
js/ui/notificationDaemon.js
js/ui/telepathyClient.js
js/ui/windowAttentionHandler.js

index f3ea1b5a0ab4566e8afc01a33da71ce5b7625f45..6bbd6448f7a56fed46436a8404ce22487a416f1f 100644 (file)
@@ -550,13 +550,12 @@ Notification.prototype = {
 };
 Signals.addSignalMethods(Notification.prototype);
 
-function Source(id, title, createIcon) {
-    this._init(id, title, createIcon);
+function Source(title, createIcon) {
+    this._init(title, createIcon);
 }
 
 Source.prototype = {
-    _init: function(id, title, createIcon) {
-        this.id = id;
+    _init: function(title, createIcon) {
         this.title = title;
         if (createIcon)
             this.createIcon = createIcon;
@@ -809,7 +808,7 @@ MessageTray.prototype = {
                     this._updateState();
             }));
 
-        this._summaryItems = {};
+        this._summaryItems = [];
         this._longestSummaryItem = null;
     },
 
@@ -827,12 +826,20 @@ MessageTray.prototype = {
     },
 
     contains: function(source) {
-        return this._summaryItems.hasOwnProperty(source.id);
+        return this._getIndexOfSummaryItemForSource(source) >= 0;
+    },
+
+    _getIndexOfSummaryItemForSource: function(source) {
+        for (let i = 0; i < this._summaryItems.length; i++) {
+            if (this._summaryItems[i].source == source)
+                return i;
+        }
+        return -1;
     },
 
     add: function(source) {
         if (this.contains(source)) {
-            log('Trying to re-add source ' + source.id);
+            log('Trying to re-add source ' + source.title);
             return;
         }
 
@@ -844,14 +851,14 @@ MessageTray.prototype = {
 
         let newItemTitleWidth = summaryItem.getTitleNaturalWidth();
         if (newItemTitleWidth > minTitleWidth) {
-            for (sourceId in this._summaryItems) {
-                this._summaryItems[sourceId].setMinTitleWidth(newItemTitleWidth);
+            for (let i = 0; i < this._summaryItems.length; i++) {
+                this._summaryItems[i].setMinTitleWidth(newItemTitleWidth);
             }
             summaryItem.setMinTitleWidth(newItemTitleWidth);
             this._longestSummaryItem = summaryItem;
         }
 
-        this._summaryItems[source.id] = summaryItem;
+        this._summaryItems.push(summaryItem);
 
         source.connect('notify', Lang.bind(this, this._onNotify));
 
@@ -872,7 +879,8 @@ MessageTray.prototype = {
     },
 
     removeSource: function(source) {
-        if (!this.contains(source))
+        let index = this._getIndexOfSummaryItemForSource(source);
+        if (index == -1)
             return;
 
         // remove all notifications with this source from the queue
@@ -883,26 +891,26 @@ MessageTray.prototype = {
         }
         this._notificationQueue = newNotificationQueue;
 
-        this._summary.remove_actor(this._summaryItems[source.id].actor);
+        this._summary.remove_actor(this._summaryItems[index].actor);
         if (this._summary.get_children().length > 0)
             this._summaryNeedsToBeShown = true;
         else
             this._summaryNeedsToBeShown = false;
 
-        delete this._summaryItems[source.id];
+        this._summaryItems.splice(index, 1);
         if (this._longestSummaryItem.source == source) {
 
             let maxTitleWidth = 0;
             this._longestSummaryItem = null;
-            for (sourceId in this._summaryItems) {
-                let summaryItem = this._summaryItems[sourceId];
+            for (let i = 0; i < this._summaryItems.length; i++) {
+                let summaryItem = this._summaryItems[i];
                 if (summaryItem.getTitleNaturalWidth() > maxTitleWidth) {
                     maxTitleWidth = summaryItem.getTitleNaturalWidth();
                     this._longestSummaryItem = summaryItem;
                 }
             }
-            for (sourceId in this._summaryItems) {
-                this._summaryItems[sourceId].setMinTitleWidth(maxTitleWidth);
+            for (let i = 0; i < this._summaryItems.length; i++) {
+                this._summaryItems[i].setMinTitleWidth(maxTitleWidth);
             }
         }
 
@@ -925,12 +933,6 @@ MessageTray.prototype = {
             this._updateState();
     },
 
-    removeSourceByApp: function(app) {
-        for (let sourceId in this._summaryItems)
-            if (this._summaryItems[sourceId].source.app == app)
-                this.removeSource(this._summaryItems[sourceId].source);
-    },
-
     removeNotification: function(notification) {
         if (this._notification == notification && (this._notificationState == State.SHOWN || this._notificationState == State.SHOWING)) {
             if (this._notificationTimeoutId) {
@@ -947,12 +949,6 @@ MessageTray.prototype = {
             this._notificationQueue.splice(index, 1);
     },
 
-    getSource: function(id) {
-        if (this._summaryItems[id])
-            return this._summaryItems[id].source;
-        return null;
-    },
-
     _getNotification: function(id, source) {
         if (this._notification && this._notification.id == id)
             return this._notification;
index a6a55c5bff2a085a5f3d647a9279c058802a189d..4e78022815b546944892c7266dce6c913d248d95 100644 (file)
@@ -107,6 +107,7 @@ NotificationDaemon.prototype = {
                                   Lang.bind(this, this._acquiredName),
                                   Lang.bind(this, this._lostName));
 
+        this._sources = {};
         this._currentNotifications = {};
 
         Shell.WindowTracker.get_default().connect('notify::focus-app',
@@ -140,13 +141,9 @@ NotificationDaemon.prototype = {
         }
     },
 
-    _sourceId: function(id) {
-        return 'source-' + id;
-    },
-
     Notify: function(appName, replacesId, icon, summary, body,
                      actions, hints, timeout) {
-        let source = Main.messageTray.getSource(this._sourceId(appName));
+        let source = this._sources[appName];
         let id = null;
 
         // Filter out notifications from Empathy, since we
@@ -167,13 +164,18 @@ NotificationDaemon.prototype = {
         // been acknowledged.
         if (source == null) {
             let title = appNameMap[appName] || appName;
-            source = new Source(this._sourceId(appName), title, icon, hints);
+            source = new Source(title, icon, hints);
             Main.messageTray.add(source);
+            this._sources[appName] = source;
 
             source.connect('clicked', Lang.bind(this,
                 function() {
                     source.destroy();
                 }));
+            source.connect('destroy', Lang.bind(this,
+                function() {
+                    delete this._sources[appName];
+                }));
 
             let sender = DBus.getCurrentMessageContext().sender;
             let busProxy = new Bus();
@@ -265,8 +267,16 @@ NotificationDaemon.prototype = {
 
     _onFocusAppChanged: function() {
         let tracker = Shell.WindowTracker.get_default();
-        if (tracker.focus_app)
-            Main.messageTray.removeSourceByApp(tracker.focus_app);
+        if (!tracker.focus_app)
+            return;
+
+        for (let id in this._sources) {
+            let source = this._sources[id];
+            if (source.app == tracker.focus_app) {
+                source.destroy();
+                return;
+            }
+        }
     },
 
     _actionInvoked: function(notification, action, source, id) {
@@ -291,15 +301,15 @@ NotificationDaemon.prototype = {
 
 DBus.conformExport(NotificationDaemon.prototype, NotificationDaemonIface);
 
-function Source(sourceId, title, icon, hints) {
-    this._init(sourceId, title, icon, hints);
+function Source(title, icon, hints) {
+    this._init(title, icon, hints);
 }
 
 Source.prototype = {
     __proto__:  MessageTray.Source.prototype,
 
-    _init: function(sourceId, title, icon, hints) {
-        MessageTray.Source.prototype._init.call(this, sourceId, title);
+    _init: function(title, icon, hints) {
+        MessageTray.Source.prototype._init.call(this, title);
 
         this.app = null;
         this._openAppRequested = false;
index e23f4fa1ad52dd5ff36bf42ce7c6c2445d37b8e0..722dffc48313407767b4a78c30f6a479edd39994 100644 (file)
@@ -445,7 +445,7 @@ Source.prototype = {
     __proto__:  MessageTray.Source.prototype,
 
     _init: function(accountPath, connPath, channelPath, targetHandle, targetHandleType, targetId) {
-        MessageTray.Source.prototype._init.call(this, targetId, targetId);
+        MessageTray.Source.prototype._init.call(this, targetId);
 
         this._accountPath = accountPath;
 
index ceba3f9ef8856624346ee8c075881accdc543b26..fa8aefaad52bda9029849de21af13e7f02923e4d 100644 (file)
@@ -14,10 +14,12 @@ function WindowAttentionHandler() {
 
 WindowAttentionHandler.prototype = {
     _init : function() {
+        this._startupIds = {};
+        this._sources = {};
+
         let display = global.screen.get_display();
         display.connect('window-demands-attention', Lang.bind(this, this._onWindowDemandsAttention));
         let tracker = Shell.WindowTracker.get_default();
-        this._startupIds = {};
         tracker.connect('startup-sequence-changed', Lang.bind(this, this._onStartupSequenceChanged));
     },
 
@@ -29,10 +31,6 @@ WindowAttentionHandler.prototype = {
         }
     },
 
-    _sourceId : function(appId) {
-        return 'attention-' + appId;
-    },
-
     _getTitle : function(app, window) {
         if (this._startupIds[window.get_startup_id()])
             return app.get_name();
@@ -61,12 +59,15 @@ WindowAttentionHandler.prototype = {
 
         let tracker = Shell.WindowTracker.get_default();
         let app = tracker.get_window_app(window);
+        let appId = app.get_id();
 
-        let source = Main.messageTray.getSource(this._sourceId(app.get_id()));
+        let source = this._sources[appId];
         if (source == null) {
-            source = new Source(this._sourceId(app.get_id()), app, window);
+            source = new Source(app, window);
+            this._sources[appId] = source;
             Main.messageTray.add(source);
             source.connect('clicked', Lang.bind(this, function() { source.destroy(); }));
+            source.connect('destroy', Lang.bind(this, function() { delete this._sources[appId]; }));
         }
 
         let notification = new MessageTray.Notification(window.get_startup_id(), source, this._getTitle(app, window), this._getBanner(app, window), true);
@@ -82,15 +83,15 @@ WindowAttentionHandler.prototype = {
     }
 };
 
-function Source(sourceId, app, window) {
-    this._init(sourceId, app, window);
+function Source(app, window) {
+    this._init(app, window);
 }
 
 Source.prototype = {
     __proto__ : MessageTray.Source.prototype,
 
-    _init: function(sourceId, app, window) {
-        MessageTray.Source.prototype._init.call(this, sourceId, app.get_name());
+    _init: function(app, window) {
+        MessageTray.Source.prototype._init.call(this, app.get_name());
         this._window = window;
         this._app = app;
     },